# 博客首页测试
from selenium.webdriver.common.by import By
from common.Utils import BlogDriver
import time

class BlogList:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.137.19.140:9090/blog_list.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)
#登录情况下
    def ListTestByLogin(self):
        #查看博客列表第一篇博客是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.title") #标题
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.date") #时间
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > div.desc") #内容
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div > a") #查看详情按钮

        #查看个人信息卡片，只要检查下个人昵称是否存在即可
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > h3")  # 查看详情按钮
        BlogDriver.getScreeShot()
#未登录情况下
    def ListTestNoLogin(self):
        #可以点击注销按钮回到登录页面，然后直接访问list文件，此时会强制回到登录页面，再判断登录页面的内容即可
        self.driver.find_element(By.CSS_SELECTOR,"body > div.nav > a:nth-child(6)").click()
        time.sleep(1)
        self.driver.get(self.url)
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.container-login > div > h3").text
        print(text)
        assert text == "登陆"
